package com.yifeng.repo.controller.postman.web;

import com.yifeng.repo.controller.postman.work.PostmanManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletContextInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * Created by daibing on 2023/5/23.
 */
@Slf4j
public class PostmanServletRegistrar implements ServletContextInitializer {
    private final String callbackPrefix;
    private final PostmanManager postmanManager;

    public PostmanServletRegistrar(String callbackPrefix, PostmanManager postmanManager) {
        this.callbackPrefix = callbackPrefix;
        this.postmanManager = postmanManager;
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        PostmanServlet servlet = new PostmanServlet(postmanManager);
        ServletRegistration.Dynamic registration = servletContext.addServlet("PostmanServlet", servlet);
        registration.addMapping(callbackPrefix + "/*");
        registration.setLoadOnStartup(1);
        log.info("yfcloud controller open status api success: Postman");
    }
}
